Loading packages

library(tidyverse)
## Registered S3 methods overwritten by 'ggplot2':
##   method         from 
##   [.quosures     rlang
##   c.quosures     rlang
##   print.quosures rlang
## Registered S3 method overwritten by 'rvest':
##   method            from
##   read_xml.response xml2
## -- Attaching packages ----------------------------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.1.1       v purrr   0.3.2  
## v tibble  2.1.1       v dplyr   0.8.0.1
## v tidyr   0.8.3       v stringr 1.4.0  
## v readr   1.3.1       v forcats 0.4.0
## -- Conflicts -------------------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(tidyr)
library(here)
## here() starts at /Users/rindtorf/github/promise
library(ggrastr)
## Warning: package 'ggrastr' was built under R version 3.6.3
library(cowplot)
## Warning: package 'cowplot' was built under R version 3.6.3
library(princurve)
library(scico)
## Warning: package 'scico' was built under R version 3.6.3
library(ggridges)
## Warning: package 'ggridges' was built under R version 3.6.3
# modeling
library(nnet)

loading input data and annotation. Note that on the central cluster, with access to the complete data table, the definition of the input can easily be changed. For remote work, the subsampled dataset “umap_drugs_sampled.Rds” is the default choice.

# I wish I could solve my path problems with the here() package, but experienced unreliable behavior 
# PATH = "/dkfz/groups/shared/OE0049/B110-Isilon2/promise/"
PATH = paste0(here::here(), "/")

#umap_df <- read_rds(paste0(PATH, "data/processed/PhenotypeSpectrum/umap_absolute_all_drugs_tidy.Rds"))
umap_df <- read_rds(paste0(PATH, "data/processed/PhenotypeSpectrum/umap_absolute_all_drugs_sampled.Rds"))

organoid_morphology <- read_delim(here::here("references/imaging/visual_classification_organoids.csv"), ";", escape_double = FALSE, trim_ws = TRUE) %>% 
  dplyr::select(line = organoid, morphology = visual_inspection_v2)
## Parsed with column specification:
## cols(
##   organoid = col_character(),
##   visual_inspection_morphology_2017 = col_character(),
##   visual_class_2_2017 = col_double(),
##   visual_inspection_v2 = col_character(),
##   visual_inspection_size_2017 = col_character(),
##   visual_class_1_2017 = col_double(),
##   visual_size_ranking_2018 = col_double(),
##   visual_cystic_ranking_2018 = col_double(),
##   clustering_jan = col_character()
## )

Partition inspection

We are able to observe 4 partitions in our data. After manual inspection, it becomes cleat that the two smallest partitions are mostly consisting of

umap_df %>% 
  ggplot(aes(v1, v2, color = factor(partition))) + 
  geom_point_rast(alpha = 0.5, size = 0.35) + 
  scale_color_brewer(type = "qual", palette = "Set2") +
  theme_cowplot() +
  labs(x = "UMAP 1",
       y = "UMAP 2",
       color = "partition") + 
  theme(legend.position = "bottom") + 
    coord_fixed()

umap_df %>% 
  dplyr::count(partition) %>% 
  mutate(ratio = n/sum(n)) %>% 
  arrange(desc(ratio))
## # A tibble: 4 x 3
##   partition      n   ratio
##   <fct>      <int>   <dbl>
## 1 1         283583 0.916  
## 2 2          21320 0.0689 
## 3 3           3385 0.0109 
## 4 4           1228 0.00397

I remove 2 partitions from all main figures for ease of reading. Below, it is easy to toggle the removal of partitions on and off to make sure this filtering step is robust

Organoid Size Distributions

I plot a size-distribution.

gg_size_dist <- umap_df %>% 
  filter(partition %in% c(1,2)) %>%
  ggplot(aes(size)) + 
  geom_histogram() + 
  theme_cowplot()

gg_size_dist_log <- gg_size_dist + 
  scale_x_log10() 

gg_size_dist_log
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

I add the eCDF.

df <- umap_df %>% filter(partition %in% c(1,2))

gg_ecdf <- ggplot(df %>% filter(drug == "DMSO")) +
  stat_ecdf(aes(x = size, group = line), 
              geom = "step", size = 1) +
  #scale_color_manual(values = c("#00AFBB", "#E7B800"))+
  labs(y = "f(size)",
       x = "organoid size [pixels]") + 
  theme_cowplot()

gg_ecdf

For more details about distributions, please refer to *reports/Phenotypespectrum/‘xyz’_dist.pdf*.

line_param <- umap_df %>% filter(partition %in% c(1,2)) %>% 
  nest(-line, -replicate) %>% 
  mutate(fit = map(data, ~ fitdistrplus::fitdist(.x$size, "lnorm")),
         param = map(fit, ~ .x$estimate %>% broom::tidy()))
## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")
df <- line_param %>% unnest(param) %>% 
  filter(names == "meanlog") %>% 
  group_by(line) %>% 
  mutate(mean_meanlog = mean(x)) %>% 
  arrange(mean_meanlog) %>% 
  ungroup() %>%
  mutate(line = factor(line, levels = .$line %>% unique()))

organoid_size_factor <- df$line %>% levels()

df <- df %>% 
    dplyr::select(line, replicate, x) %>%
    # tidyr::pivot_wider(names_from = replicate, 
    #             values_from = x)
    tidyr::spread(key = replicate, value = x)

r_size = df %>% ungroup() %>% dplyr::select(-line) %>% as.matrix %>% cor() %>% min()

gg_size_replicate <- df %>% 
  ggplot(aes(`1`, `2`)) +
  geom_smooth(method = "lm", se = FALSE, color = "grey") +
  geom_point() + 
  theme_cowplot() + 
  labs(x = "Replicate 1, mu [ln size]",
       y = "Replicate 2, mu [ln size]",
       caption = paste0("2 replicates, r= ", round(r_size, 2))) + 
  coord_fixed(ratio = 1) 
  #geom_abline(slope = 1, color = "grey")
  

gg_size_replicate

organoid_size_factor_09 <- umap_df %>% filter(partition %in% c(1,2)) %>% group_by(line) %>% 
  summarise(x = quantile(size_log, 0.9)) %>% 
  #summarise(x = mean(size_log)) %>% 
  arrange(x) %>% .$line


gg_size_dist_morph_ridge <- umap_df %>% filter(partition %in% c(1,2)) %>% filter(drug == "DMSO") %>% 
  mutate(line = factor(line, levels = organoid_size_factor_09)) %>% 
  ggplot() +
  geom_density_ridges_gradient(aes(y = line, x = size_log, fill = stat(x)), scale = 1) +
  #geom_density(aes(x = size_log, group = replicate, color = morphological_class)) + 
  #facet_wrap(~ line) + 
  scale_fill_viridis_c() +
  labs(caption = "DMSO treated organoids",
       x = "ln(size)",
       fill = "size") + 
  theme(legend.position = "bottom") +
  theme_cowplot() 

gg_size_dist_morph_ridge
## Picking joint bandwidth of 0.194

umap_size <- function(umap){
  umap %>%
  #filter(Size < 1000) %>%
  ggplot(aes(v1, v2, color = size_log)) + 
  geom_point_rast(alpha = 0.5, size = 0.35) + 
  scale_color_viridis_c() +
  theme_cowplot() +
  labs(x = "UMAP 1",
       y = "UMAP 2",
       color = "ln(size)") + 
  theme(legend.position = "bottom") + 
    coord_fixed()
}

gg_size <- umap_size(umap_df %>% filter(partition %in% c(1,2)))

Organoid Size during Drug Treatment

drug_size <- umap_df %>% filter(partition %in% c(1,2)) %>% filter(drug == "DMSO" | drug == "Paclitaxel") %>% 
  mutate(concentration = ifelse(drug == "DMSO", 0, concentration)) %>%
  #filter(morphological_class == "disorganized") %>% 
  #filter(morphological_class != "other") %>% 
  mutate(concentration = factor(concentration, levels = c("0", "0.0016", "0.008", "0.04", "0.2", "1.0")))

ggdrug_size <- ggplot(drug_size) +
  geom_density(aes(x = log(size), group = concentration, color = concentration), size = 1.5) + 
  scico::scale_color_scico_d() +
  theme_cowplot() + 
  #scale_x_continuous(limits = c(0, 15000)) +
  theme(legend.position = "bottom") + 
  labs(color = "Paclitaxel Concentration Factor",
       title = "Organoid size distribution",
       x = "ln(size)")

ggdrug_size 

drug_count <- drug_size %>%
  dplyr::count(concentration, line, replicate, well)

ggdrug_count <- ggplot(drug_count) +
  geom_density(aes(x = log(n), group = concentration, color = concentration), size = 1.5) + 
  scico::scale_color_scico_d() +
  theme_cowplot() + 
  theme(legend.position = "bottom") + 
  labs(color = "Paclitaxel Concentration Factor",
       title = "Organoid count distribution",
       x = "ln(n)")

ggdrug_count

set.seed(234)
loi = c("D022T01", "D046T01")


df <- umap_df  %>%
  filter(partition %in% c(1,2)) %>%
  filter(drug == "DMSO" | drug == "Paclitaxel") %>% 
  mutate(concentration = ifelse(drug == "DMSO", 0, concentration)) %>% 
  filter(line == loi)
## Warning in line == loi: longer object length is not a multiple of shorter
## object length
gg_drug <- umap_df %>% filter(partition %in% c(1,2)) %>%
  dplyr::select(-line, -concentration) %>%
  ggplot(aes(v1, v2)) + 
  geom_point_rast(alpha = 1, size = 0.35, color = "#f1f1f1") + 
  geom_point_rast(data = df  %>%
    group_by(concentration) %>% 
    sample_n(1000, replace = TRUE),
  aes(color = concentration),alpha = 1, size = 1.5, shape=16) + 
  #facet_wrap( ~ concentration, ncol = 1) + 
  #scale_color_brewer(type = "seq", palette = "YlOrRd") + 
  #geom_density2d(color = "black") + 
  theme_classic() +
  labs(x = "UMAP 1",
       y = "UMAP 2",
       caption = paste0(paste(loi, collapse=" "), ", Paclitaxel"),
       color = "Concentration Factor") + 
  scico::scale_color_scico_d() + 
  facet_wrap(~ line, ncol = 2) +
  theme(legend.position = "bottom") +
  #theme_cowplot(font_size = 8) + 
  theme(legend.position = "bottom")
 
gg_drug

loi <- c("D022T01", "D055T01")

drug_size_param <- drug_size %>% 
  nest(-concentration, -line) %>% 
  mutate(fit = map(data, ~ fitdistrplus::fitdist(.x$size, "lnorm")),
         param = map(fit, ~ .x$estimate %>% broom::tidy()))
## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")

## Warning: 'tidy.numeric' is deprecated.
## See help("Deprecated")
df <- drug_size_param %>% unnest(param) %>% 
  filter(names == "meanlog") %>%
  mutate(concentration = factor(concentration, levels = c("0", "0.0016", "0.008", "0.04", "0.2", "1.0"))) 

gg_size_drug <- df %>%
  filter(line %in% loi) %>%
  #mutate(concentration = as.numeric(as.character(concentration))) %>%
  ggplot(aes(concentration, x)) + 
    geom_point(color = "grey") + 
  geom_line(data = df %>% dplyr::rename(line_h = line) , aes(group = line_h), color = "grey") +
  geom_point(data = df %>% dplyr::rename(line_h = line), color = "grey") +
  geom_point(color = "black") +
  geom_line(aes(group = line), color = "black") +
  labs(y = 'mu ln(size)' ,
       x = "Concentration Factor",
       caption = paste0(paste(loi, collapse=" "), ", Paclitaxel")) +
  facet_wrap(~ line)+
  theme_cowplot()

gg_size_drug

Organoid Heterogeneity

I plot 2 organoid lines treated with DMSO control

set.seed(234)


df <- umap_df  %>% filter(partition %in% c(1,2)) %>%
  mutate(cystic = if_else(line == "D013T01" &  well == "D24" & plate == "D013T01P001L02", TRUE, FALSE)) %>%
  mutate(compact = if_else(line == "D055T01" &  well == "D24" & plate == "D055T01P007L02", TRUE, FALSE))

gg_cys_comp <- df %>% 
  sample_frac(0.01) %>%
  ggplot(aes(v1, v2, color = size_log)) + 
  #scale_color_brewer(type = "qual", palette = 2) +
  geom_point_rast(alpha = 0.1, size = 0.35) + 
  geom_point_rast(color = "#F4B400", alpha = 1, size = 0.5, data = df %>% filter(cystic == TRUE)) +
  geom_point_rast(color = "#DB4437", alpha = 1, size = 0.5, data = df %>% filter(compact == TRUE)) + 
  scale_color_viridis_c() +
  labs(color = "size",
       caption = "yellow: D013T01, red: D055T01",
       x = "UMAP 1",
       y = "UMAP 2") +
  theme_cowplot() + 
  coord_fixed()

gg_cys_comp

In general, DMSO treated organoid lines cover the same latent space than drug treated organoids. This is likely influenced by the large number of untreated organoids in the dataset.

set.seed(123)

df <- umap_df %>% filter(partition %in% c(1,2))


gg_size_supp <- df %>%
  mutate(drug = if_else(drug == "DMSO", "DMSO", "other")) %>%
  ggplot(aes(v1, v2, color = size_log)) + 
  geom_point_rast(alpha = 0.5, size = 0.35) + 
  scale_color_viridis_c() +
  theme_cowplot() +
  labs(x = "UMAP 1",
       y = "UMAP 2") + 
  theme(legend.position = "bottom") +
  facet_wrap(~ drug)

gg_size_supp + ggsave(paste0(PATH, "reports/figures/gg_size_all.pdf"))
## Saving 7 x 5 in image

Organoid line differences

I create a single plot showing the two extreme organoid lines and their distribution within the embedding.

set.seed(123)

loi <- c("D055T01", "D007T01",  "D027T01", "D018T01") #c("D055T01", "D007T01",  "D021T01", "D019T01", "D027T01")
#loi <- umap_df$line %>% unique()

df <- umap_df %>%
  filter(drug == "DMSO") %>% 
  filter(partition %in% c(1,2))


gg_line <- df %>% dplyr::select(-line) %>%
  ggplot(aes(v1, v2)) + 
  geom_point_rast(alpha = 1, size = 0.35, color = "#f1f1f1") + 
  geom_point_rast(data = umap_df %>%
                    filter(drug == "DMSO") %>% 
                   # filter(line %in% c("D021T01")) %>%
    filter(line %in% loi) %>% 
    mutate(line = factor(line, levels = loi)) %>% 
      sample_frac(0.1),
    #mutate(line = factor(line, levels = c("D021T01"))),
  aes(color = line),alpha = .4, size = 0.35, shape=16) + 
  facet_wrap( ~ line, ncol =2) +
  scale_color_brewer(type = "qual", palette = "Set2") +
  #scale_color_manual(values = c(c("#D80D12", "#461C01", "#9a4c91", "#70BE6F", "#24345E"))) +   
  #geom_density2d(color = "black") + 
  theme_classic() +
  labs(x = "UMAP 1",
       y = "UMAP 2")+
       #caption = "control treated organoids") + 
  theme_cowplot(font_size = 8) + 
  theme(legend.position = "nothing")

gg_line + ggsave(paste0(PATH, "reports/figures/gg_size_all.pdf"), width = 4, height = 4)

I am focusing on cystic vs solid organoid lines

#UMAP Cystic (Lines 18, 13, 27, 30) vs. Solid (others) treated with DMSO, for Figure 1 / matching expression analysis done for cystic vs. rest

set.seed(123)

# TODO reference morphology from
cystic_l <- organoid_morphology %>% filter(morphology == "cystic") %>%.$line %>% paste0(., "01")
dense_l <- organoid_morphology %>% filter(morphology == "solid") %>%.$line %>% paste0(., "01")

df <- umap_df %>%
  filter(drug == "DMSO") %>% 
  filter(partition %in% c(1,2)) %>%
  mutate(morphology = case_when(line %in% cystic_l ~ "cystic",
                                line %in% dense_l ~ "dense",
                                 TRUE ~ "other"))

gg_cystic <- umap_df %>% 
  ggplot(aes(v1, v2)) + 
  geom_point_rast(alpha = 1, size = 0.35, color = "#f1f1f1") + 
  
  # geom_point_rast(data = df %>%
  #   filter(morphology == "cystic") %>% 
  #     sample_frac(0.05),
  # aes(color = morphology),alpha = .4, size = 0.35, shape=16) + 
  
  geom_density_2d(data = df %>%
    filter(morphology != "other") %>% 
      sample_frac(0.05),
  aes(color = morphology), size = 1.5) +

  scale_color_brewer(type = "qual", palette = "Set2") +
  #scale_color_manual(values = c(c("#D80D12", "#461C01", "#9a4c91", "#70BE6F", "#24345E"))) +   
  #geom_density2d(color = "black") + 
  theme_classic() +
  labs(x = "UMAP 1",
       y = "UMAP 2")+
       #caption = "control treated organoids") + 
  theme_cowplot(font_size = 8) + 
  #theme(legend.position = "nothing")  + 
  coord_fixed()


gg_cystic

Plot Export

#gg_size_dist + ggsave(paste0(PATH, "reports/figures/gg_size_dist.pdf"))
#gg_size_dist_log +  ggsave(paste0(PATH, "reports/figures/gg_size_dist_log.pdf"))
#ggdrug_size + ggsave(paste0(PATH, "reports/figures/gg_drug_dist_size_log.pdf"))
#gg_ecdf + ggsave(paste0(PATH, "reports/figures/gg_size_dist_ecdf.pdf"))
#gg_size_dist_morph_ridge +  ggsave(paste0(PATH, "reports/figures/gg_size_dist_morph_ridge.pdf"), width = 4, height = 4)

# ggdrug_count + ggsave(paste0(PATH, "reports/figures/gg_drug_dist_n_log.pdf"))
# gg_drug + ggsave(paste0(PATH, "reports/figures/gg_drug.pdf"), width = 8, height = 4)
# gg_size_drug + ggsave(paste0(PATH, "reports/figures/gg_trametinib_size_dose.pdf"), width = 3.65, height = 3.65)
gg_cystic + ggsave(paste0(PATH, "reports/figures/gg_cystic.pdf"), width = 4, height = 4)

plot_grid(plot_grid(gg_size_dist_morph_ridge, gg_size_replicate, labels = c('A', 'B'), label_size = 12, ncol = 2),
          gg_size,
          plot_grid(gg_line, gg_cystic, labels = c('D', 'E'), label_size = 12, ncol = 2),
          labels = c('', 'C', ''), label_size = 12, ncol = 1) +
  ggsave(paste0(PATH, "reports/panels/panel_size_dist.pdf"), width = 8, height = 16)

plot_grid(plot_grid(ggdrug_size, ggdrug_count, labels = c('A', 'B'), label_size = 12),
          gg_drug,
          gg_size_drug,
          labels = c('', 'C', 'D'), label_size = 12, ncol = 1) +
  ggsave(paste0(PATH, "reports/panels/panel_size_drug.pdf"), width = 8, height = 12)

gg_size_supp

Supplement

Here I collect pieces of code that did not make it into the final analysis but can be run in theory. In order to access these peaces of code, you have to open the .RMD file.

knitr::knit_exit()